<template>
  <div class="control">
    <transition name="fade">
      <div v-if="active" :class="['popup']">
        <p class="popup__text">Категория ценности: {{ parent }}</p>
      </div>
    </transition>

    <p class="name" @mouseover="active = true" @mouseout="active = false">{{ name }}</p>
    <input @mousemove="change" @click="change" :style="{ accentColor: colorRange }" type="range" class="range" min="0"
      max="100" v-model.number="store['one' + id]" />
    <input @change="change" @keydown="change" type="number" class="number" min="0" max="100"
      v-model="store['one' + id]" />
  </div>
</template>

<script>

import { useStore } from '@/state/stateStore';

export default {
  name: 'ControllerVue',
  props: {
    name: String,
    colorRange: String,
    id: Number,
    func: Function,
    parent: String
  },
  methods: {
    change() {
      this.func()
    },
  },
  data() {
    return {
      active: false
    }
  },
  setup() {
    const store = useStore();

    return { store }
  }
}

</script>

<style scoped>
.control {
  position: relative;
  display: flex;
  padding: 2px;
  margin-top: 2px;
}

.popup {
  position: absolute;
  top: -43px;
  left: -5px;
  min-width: 100px;
  padding: 10px;
  max-width: max-content;
  height: max-content;
  border-radius: 20px;
  background-color: #64b0d9;
}

.popup:after {
  content: "";
  position: absolute;
  top: 28px;
  left: 28px;
  width: 18px;
  height: 18px;
  background-color: #64b0d9;
  transform: rotate(45deg);
}

.popup__text {
  margin: 0;
  padding: 0;
  color: white;
  font-weight: bold;
}

.name {
  margin: 0;
  padding: 0;
  width: 340px;
  text-align: start;
  font-size: 17px;
  line-height: 20px;
  cursor: pointer;
}

.range {
  margin: 0;
  padding: 0;
  width: 230px;
  cursor: pointer;
}

.number {
  margin: 0;
  padding: 0;
  width: 40px;
  margin-left: 10px;
  cursor: pointer;
  border-radius: 10px;
  padding-left: 5px;
  border: none;
  outline: 2px solid white;
  transition-property: outline;
  transition-duration: .6s;
}

.number:focus-visible {
  border: none;
  outline: 2px solid #FF9C00;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>
